package gui.properties;

import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import model.objects.EdiTransfer;

public class TransferPropertiesPanel extends FlowPanel{

	

		private EdiTransfer transfer;
		public TransferPropertiesPanel(EdiTransfer transfer) {
			super("Transfer");
			this.transfer = transfer;
			this.setPanelComponents(this.initPanelComponents());
			
		}
		private List<Component> initPanelComponents() {
			List<Component> comps = new LinkedList<Component>();		
			
			JPanel toPanel = new JPanel();
			toPanel.setLayout(new GridLayout(0,2));
			toPanel.add(new JLabel("To:"));
			toPanel.add(new JLabel(transfer.getToStation().getName()));
			
			
			
			
			JPanel fromPanel = new JPanel();
			fromPanel.setLayout(new GridLayout(0,2));
			fromPanel.add(new JLabel("From:"));
			fromPanel.add(new JLabel(transfer.getFromStation().getName()));
			
			
			JPanel timePanel = new JPanel();
			timePanel.setLayout(new GridLayout(0,2));
			timePanel.add(new JLabel("Time:"));
			timePanel.add(new TimeField());
						
			comps.add(fromPanel);
			comps.add(toPanel);
			comps.add(timePanel);
			
			return comps;
		}
		
		
		class TimeField extends JTextField {
			public TimeField() {
				//final JTextField nameField = this;
				setText(""+transfer.getTime());
				addKeyListener(new KeyListener() {

					@Override
					public void keyPressed(KeyEvent arg0) {
						if(arg0.getKeyCode()==KeyEvent.VK_ENTER) {
							model.MetroModel.getInstance().setTransferTime(transfer, Integer.parseInt(getText()));
						}				
					}

					@Override
					public void keyReleased(KeyEvent arg0) {
						
						
					}

					@Override
					public void keyTyped(KeyEvent arg0) {
						
					}
					
				});
				
			}
			
		}
		
		
		

	}
